package indi.zhifa.study2024.nbr.util.billNo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class BillNoGenObject {

    public BillNoGenObject(String pPrefix){
        mPrefix = pPrefix;
        mResetTime = LocalDateTime.now();
        idx = 0;
    }

    String mPrefix;
    int idx;
    LocalDateTime mResetTime;

    synchronized public String next(){
        LocalDateTime currentTime = LocalDateTime.now();
        if(!currentTime.toLocalDate().equals(mResetTime.toLocalDate())){
            mResetTime = currentTime;
            idx = 0;
        }
        return mPrefix+currentTime.toLocalDate().format(DateTimeFormatter.ofPattern("yyMMdd"))+String.format("%05d", ++idx);
    }
}
